package com.bjx.system.controller;

import cn.hutool.core.lang.tree.Tree;
import com.bjx.common.core.domain.R;
import com.bjx.common.core.domain.group.Update;
import com.bjx.system.domain.query.OrgQuery;
import com.bjx.system.domain.vo.OrgVO;
import com.bjx.system.service.IOrgService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc: 组织信息控制器
 * @author: liushuai
 * @date: 2022/09/29
 */
@RequestMapping("/org")
@Tag(name = "组织信息控制器")
@RestController
public class OrgController {

    @Autowired
    private IOrgService orgService;

    /**
     * 分页查询组织信息列表
     * @param orgQuery
     * @return: R<IPage<OrgVO>>
     * @Author: liushuai
     * @Date: 2022/09/29
     */
    @Operation(summary = "分页查询组织信息列表")
    @GetMapping("listOrg")
    public R<List<OrgVO>> listOrg(OrgQuery orgQuery) {
        List<OrgVO> list = orgService.listOrg(orgQuery);
        return R.success(list);
    }

    /**
     * 根据组织信息id查询组织信息
     * @param orgId
     * @return:R<OrgVO>
     * @Author: liushuai
     * @Date: 2022/09/29
     */
    @Operation(summary = "根据组织信息id查询组织信息")
    @GetMapping("selectOrgByOrgId")
    public R<OrgVO> selectOrgByOrgId(@RequestParam Long orgId){
        OrgVO vo = orgService.selectOrgByOrgId(orgId);
        return R.success(vo);
    }

    /**
     * 根据组织信息id删除组织信息
     * @param orgId
     * @return: R
     * @Author: liushuai
     * @Date: 2022/09/29
     */
    @Operation(summary = "根据组织信息id删除组织信息")
    @GetMapping("deleteOrgByOrgId")
    public R deleteOrgByOrgId(@RequestParam Long orgId){
        orgService.deleteOrgByOrgId(orgId);
        return R.successMsg("删除组织信息成功");
    }

   /**
    * 新增组织信息
    * @param orgVO
    * @return: R
    * @Author: liushuai
    * @Date: 2022/09/29
    */
   @Operation(summary = "新增组织信息")
   @PostMapping("insertOrg")
   public R insertOrg(@RequestBody @Validated OrgVO orgVO){
      orgService.insertOrg(orgVO);
      return R.successMsg("新增组织信息成功");
   }

    /**
     * 修改组织信息
     * @param orgVO
     * @return: R
     * @Author: liushuai
     * @Date: 2022/09/29
     */
    @Operation(summary = "修改组织信息")
    @PostMapping("updateOrg")
    public R updateOrg(@RequestBody @Validated(Update.class) OrgVO orgVO){
        orgService.updateOrg(orgVO);
        return R.successMsg("修改组织信息成功");
    }


    /**
     * 获取组织机构树
     * @param
     * @return: com.bjx.common.core.domain.R
     * @Author: liushuai
     * @Date: 2022/10/7 14:33
     */
    @Operation(summary = "获取组织机构树")
    @GetMapping("listTreeOrg")
    public R<List<Tree<Long>>> listTreeOrg(@RequestParam Long orgId, @RequestParam Boolean isCompany){
        List<Tree<Long>> tree = orgService.listTreeOrg(orgId,isCompany);
        return R.success(tree);
    }


}
